-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make the CLI mode available via the SAPI globals #14479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When hooking into RINIT it is currently pretty much impossible to determine whether a file will actually be executed or if it just will be linted, highlighted, or comments stripped: The startup is identical for all of them and the chosen mode is not currently exposed to other extensions. The `SG(server_context)` is currently entirely unused for the `cli` SAPI. It appears to be appropriate to store the mode as a SAPI-specific information inside of it.
The patch seems right, but I wonder why you need to know this in RINIT? |
My use case includes a fairly expensive and ultimately useless startup phase if no script is actually executed. In fact such a use case also exists within PHP itself: ext/session when combined with
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, would possibly be interesting to improve the session extension to not setup stuff when linting.
param_error = "Source stripping only works for files.\n"; | ||
break; | ||
} | ||
behavior=PHP_MODE_STRIP; | ||
context.mode=PHP_CLI_MODE_STRIP; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nits: while at it, could you add spaces around =
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll do this in a follow-up PR. Looking at the function there are more issues than the missing space for context.mode
and I want to keep git blame
useful.
Okay I see. However in that case I don't think this patch is entirely right. The server mode of the CLi SAPI does use server_context to store client data. How is your RINIT code gonna know which data structure is stored in the context? |
The CLI Server uses php-src/sapi/cli/php_cli_server.c Line 804 in a580d4a
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay then this is fine
Will this need a docs update about cli mode? It's already quite special: https://www.php.net/manual/en/features.commandline.differences.php |
I don't see what the docs have to do with this change? This is an internal change to the SAPI, the docs cover userland. |
@TimWolla said:
Until I looked at the diff a little deeper, I thought this would affect that now. In other words, if someone were relying on that kind of behavior, it might break. |
When hooking into RINIT it is currently pretty much impossible to determine whether a file will actually be executed or if it just will be linted, highlighted, or comments stripped: The startup is identical for all of them and the chosen mode is not currently exposed to other extensions.
The
SG(server_context)
is currently entirely unused for thecli
SAPI. It appears to be appropriate to store the mode as a SAPI-specific information inside of it.